Skip to content

Conversation

@michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented May 21, 2025

Resolves #13214

@vunguyenhung The BotStar API appears to have been updated since the test request was created. The test request should be:

import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    botstar: {
      type: "app",
      app: "botstar",
    }
  },
  async run({steps, $}) {
    return await axios($, {
      url: `https://apis.botstar.com/v1/bots`,
      headers: {
        Authorization: `Bearer ${this.botstar.$auth.access_token}`,
      },
    });
  },
})

And the instructions for getting the api token should be:

Go to app.botstar.com/account/profile to get the API token, API Token > copy the Token.

Summary by CodeRabbit

  • New Features

    • Introduced BotStar integration with full API support and dynamic property options.
    • Added an action to send text messages to specific users via BotStar.
    • Added sources to emit events when new bots, CMS entities, or CMS entity items are created in BotStar.
    • Included sample event data for testing and demonstration purposes.
  • Chores

    • Updated the BotStar integration version to 0.7.0.

@vercel
Copy link

vercel bot commented May 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview May 21, 2025 8:26pm
pipedream-docs ⬜️ Ignored (Inspect) May 21, 2025 8:26pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) May 21, 2025 8:26pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 21, 2025

Walkthrough

This update introduces a comprehensive BotStar integration, adding new action and source components for sending messages and emitting events related to bots and CMS entities. The BotStar app module is fully implemented with API interaction, dynamic property loading, and pagination. Supporting test data and configuration files are also included.

Changes

File(s) Change Summary
components/botstar/actions/send-message/send-message.mjs Added a new action component to send messages to a user via BotStar API.
components/botstar/botstar.app.mjs Fully implemented BotStar app integration: API methods, property definitions, pagination, and authentication.
components/botstar/package.json Bumped package version from 0.6.0 to 0.7.0.
components/botstar/sources/common/base.mjs Introduced a reusable base configuration for BotStar source components with timer and app integration.
components/botstar/sources/new-bot-created/new-bot-created.mjs Added a new source component to emit events when a new BotStar bot is created.
components/botstar/sources/new-bot-created/test-event.mjs Added a test event object for the "New Bot Created" source.
components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs Added a new source component to emit events when a new CMS entity is created in BotStar.
components/botstar/sources/new-cms-entity-created/test-event.mjs Added a test event object for the "New CMS Entity Created" source.
components/botstar/sources/new-cms-entity-item-created/new-cms-entity-item-created.mjs Added a new source component to emit events when a new CMS entity item is created in BotStar.
components/botstar/sources/new-cms-entity-item-created/test-event.mjs Added a test event object for the "New CMS Entity Item Created" source.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SendMessageAction
    participant BotStarApp
    participant BotStarAPI

    User->>SendMessageAction: Trigger "Send Message" action
    SendMessageAction->>BotStarApp: call sendMessage(recipientId, message)
    BotStarApp->>BotStarAPI: POST /messages with recipientId, message
    BotStarAPI-->>BotStarApp: API response
    BotStarApp-->>SendMessageAction: Return response
    SendMessageAction-->>User: Output summary and response
Loading
sequenceDiagram
    participant SourceComponent
    participant BotStarApp
    participant BotStarAPI
    participant Platform

    Platform->>SourceComponent: Poll for new events
    SourceComponent->>BotStarApp: listBots() / listCmsEntities() / listCmsEntityItems()
    BotStarApp->>BotStarAPI: GET /bots or /cms_entities or /items
    BotStarAPI-->>BotStarApp: Return data
    BotStarApp-->>SourceComponent: Pass data
    SourceComponent->>Platform: Emit event(s) with metadata
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement webhook sources: new-request-for-human-takeover-instant, updated-user-attribute-instant, new-subscriber-instant (#13214) None of the webhook sources described in the issue are present in the code changes.

Poem

A rabbit hops through BotStar fields,
Sending messages with lightning speed,
New bots and entities spring to life,
Events abound, the logs are rife!
From CMS to chat, integration’s bright—
Version bumped, all code in sight!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 4cd36f2 and 6cff12e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • components/botstar/package.json (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/botstar/package.json
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (5)
components/botstar/package.json (1)

3-3: Version bump to 0.7.0
The upgrade from 0.6.0 to 0.7.0 correctly reflects the addition of new BotStar components. Please ensure that your CHANGELOG or release notes are updated to document these new features and any migration steps.

components/botstar/sources/new-bot-created/new-bot-created.mjs (1)

21-27: Consider adding pagination for bot listing

The current implementation fetches all bots at once using listBots(). While this might be sufficient if users typically have a small number of bots, consider using pagination (similar to the CMS entity items component) for better scalability if the API supports it.

- async run() {
-   const bots = await this.botstar.listBots();
-   for (const bot of bots) {
-     const meta = this.generateMeta(bot);
-     this.$emit(bot, meta);
-   }
- },
+ async run() {
+   const results = this.botstar.paginate({
+     fn: this.botstar.listBots,
+     args: {},
+   });
+   for await (const bot of results) {
+     const meta = this.generateMeta(bot);
+     this.$emit(bot, meta);
+   }
+ },
components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs (2)

37-40: Consider explaining the reverse() usage

The code uses entities.reverse() before iterating, which appears to process newer entities first. Consider adding a comment explaining this choice for clarity:

- for (const entity of entities.reverse()) {
+ // Process newest entities first
+ for (const entity of entities.reverse()) {

30-41: Consider adding pagination for entity listing

Similar to the bot listing component, consider using pagination for better scalability if the API supports it and if users might have a large number of CMS entities.

- async run() {
-   const entities = await this.botstar.listCmsEntities({
-     botId: this.botId,
-   });
-   if (!entities?.length) {
-     return;
-   }
-   for (const entity of entities.reverse()) {
-     const meta = this.generateMeta(entity);
-     this.$emit(entity, meta);
-   }
- },
+ async run() {
+   const results = this.botstar.paginate({
+     fn: this.botstar.listCmsEntities,
+     args: {
+       botId: this.botId,
+     },
+   });
+   
+   // Track if we've processed any entities
+   let hasEntities = false;
+   
+   // Collect entities to process newest first
+   const entities = [];
+   for await (const entity of results) {
+     hasEntities = true;
+     entities.push(entity);
+   }
+   
+   if (!hasEntities) {
+     return;
+   }
+   
+   // Process newest entities first
+   for (const entity of entities.reverse()) {
+     const meta = this.generateMeta(entity);
+     this.$emit(entity, meta);
+   }
+ },
components/botstar/botstar.app.mjs (1)

82-104: paginate() has off-by-one and undefined-property risks

  1. count starts at 1, so with max = 1 the generator yields nothing.
  2. items?.length is assigned to total, but if the API returns { data: [...] } the loop condition misfires.
  3. args.params is mutated in-place, risking side effects for callers.

Consider:

-      limit: 100,
+      limit: args?.params?.limit ?? 100,

and:

-      let total, count = 1;
+      let pageSize;
+      let emitted = 0;
...
-        const items = await fn(args);
+        const items = await fn(args) ?? [];
+        pageSize = items.length;
...
-          if (max && ++count >= max) {
+          if (max && ++emitted >= max) {

Finally, return early if pageSize is zero to avoid an infinite loop.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 70d6955 and 4cd36f2.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (10)
  • components/botstar/actions/send-message/send-message.mjs (1 hunks)
  • components/botstar/botstar.app.mjs (1 hunks)
  • components/botstar/package.json (1 hunks)
  • components/botstar/sources/common/base.mjs (1 hunks)
  • components/botstar/sources/new-bot-created/new-bot-created.mjs (1 hunks)
  • components/botstar/sources/new-bot-created/test-event.mjs (1 hunks)
  • components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs (1 hunks)
  • components/botstar/sources/new-cms-entity-created/test-event.mjs (1 hunks)
  • components/botstar/sources/new-cms-entity-item-created/new-cms-entity-item-created.mjs (1 hunks)
  • components/botstar/sources/new-cms-entity-item-created/test-event.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (9)
components/botstar/sources/new-bot-created/test-event.mjs (1)

1-5: Add test-event fixture for “New Bot Created” source
The sample event object provides the expected id, name, and team_name fields. Ensure this fixture matches the actual BotStar API response schema for bot creation to avoid mismatches in your source component’s event emission.

components/botstar/sources/new-cms-entity-item-created/test-event.mjs (1)

1-8: Add test-event fixture for “New CMS Entity Item Created” source
This object includes all necessary properties (name, status, entity_id, _id, short_description, photo). Verify that the photo URL is accessible and that the field names align exactly with the CMS entity item payload returned by the BotStar API.

components/botstar/sources/new-cms-entity-created/test-event.mjs (1)

1-26: Add test-event fixture for “New CMS Entity Created” source
The exported object accurately represents a CMS entity with id, name, and a fields array. Confirm that each field’s data_type matches the API’s types (text, single_option, free_text, image) to ensure compatibility with downstream processing.

components/botstar/sources/common/base.mjs (2)

1-2: Import BotStar app and default polling interval
Correctly imports the botstar.app.mjs integration and the DEFAULT_POLLING_SOURCE_TIMER_INTERVAL. Please verify that the relative path resolves properly in your build/runtime environment.


4-13: Define base props for all BotStar sources
The botstar prop and the timer interface are configured as expected. If users may need a custom polling interval, consider exposing intervalSeconds as a configurable prop with documentation.

components/botstar/actions/send-message/send-message.mjs (1)

1-37: Well-structured BotStar message action component

This new action component follows good practices for integration development. It provides clear descriptions for both the component itself and its properties, making it user-friendly. The implementation correctly handles authentication through the BotStar app object and follows the API structure as documented.

The run method properly exports a summary and returns the response, which is important for workflow visibility.

components/botstar/sources/new-cms-entity-item-created/new-cms-entity-item-created.mjs (2)

39-51: Good use of pagination for handling large datasets

The implementation of the run method uses the paginate helper from the BotStar app, which is excellent for handling potentially large sets of CMS entity items. This approach is more robust than fetching all items at once as it handles API limits gracefully.


20-28: Well-implemented dependent properties

The entityId property is correctly dependent on botId, using a callback function to pass the selected bot ID when retrieving available entities. This creates a good user experience by dynamically updating available options.

components/botstar/sources/new-cms-entity-created/new-cms-entity-created.mjs (1)

34-36: Good defensive programming with null/empty check

The null check for entities?.length is a good practice to prevent errors when no entities exist. This kind of defensive programming improves reliability.

Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@michelle0927 michelle0927 merged commit 0369293 into master May 23, 2025
10 of 11 checks passed
@michelle0927 michelle0927 deleted the issue-13214 branch May 23, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Components] botstar

3 participants